package com.wl.zk;

import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author admin
 * @description
 * @date 2022/4/30 17:26
 */
@Slf4j
@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        String connectString = "127.0.0.1:2181";
        try {
            ZooKeeper zooKeeper = new ZooKeeper(connectString,2000,null);
            Stat stat = new Stat();
            String nodePath = "/zk_test";
            byte[] data = zooKeeper.getData(nodePath, null, stat);
            System.out.println(new String(data));
            zooKeeper.setData(nodePath,"hello zookeeper".getBytes(StandardCharsets.UTF_8),1);
            byte[] data1 = zooKeeper.getData(nodePath, null, stat);
            System.out.println(new String(data1));
        } catch (IOException | KeeperException | InterruptedException e) {
            e.printStackTrace();
        }

    }
}
